<?php
// $Id: $

include_once(APP_LIB_DIR . 'ManageUserRightModel.class.php');

class ManageUserRightAction extends Action
{
    function getRequestMethods ()
    {
        return REQ_GET|REQ_POST;
    }

    function isSecure ()
    {
        return false;
    }

    function getPrivilege (&$controller, &$request, &$user)
    {
        return Array('USERRIGHTSMANAGER');
    }
    
    function getDefaultView (&$controller, &$request, &$usergroup)
    {
        return VIEW_INPUT;
    }
	
    function execute (&$controller, &$request, &$usergroup)
    {
        $tm = new ManageUserRightModel('ManageUserRight');
		
        $usertype = $request->getParameter('usertype_id');
        $usertype_level = $request->getParameter('usertypelevel_id');
        $user_right = $request->getParameter('rights_id');
	$save = $request->getParameter('save');
		
        if ($save) {        
			$tm->clearlist($usertype,$usertype_level);
			if (count($user_right) > 0){
				foreach ($user_right as $id)$tm->updateme($id);
			}

		}

        $request->setAttribute('modulelist', $tm->getlist($usertype,$usertype_level));
        $request->setAttribute('moduletype', $tm->moduletypelist($usertype));
        $request->setAttribute('usertype', $tm->usertypelist());
        $request->setAttribute('usertype_level', $tm->usertypelevellist());
        return VIEW_INPUT;
    }
}

?>
